package com.kazalan.content.persistence;

import java.util.List;

import org.apache.log4j.Logger;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import org.springframework.transaction.annotation.Transactional;

import com.kazalan.domain.document.Document;
import com.kazalan.domain.document.DocumentAggregate;

@Transactional
public class HibernateDocumentDaoImpl extends HibernateDaoSupport implements DocumentDao {

	private static Logger log = Logger.getLogger(HibernateDocumentDaoImpl.class);
	
	@Override
	public DocumentAggregate getDocumentAggregateById(String documentAggregateId) {
		return getHibernateTemplate().get(DocumentAggregate.class,documentAggregateId);
	}
	
	@Override
	public void saveDocumentAggregate(DocumentAggregate documentAggregate) {
		log.debug("HibernateDocumentRepository.saveDocumentAggregate()");
		getHibernateTemplate().saveOrUpdate(documentAggregate);
	}
	
	@Override
	public Document getDocumentById(String id) {
		log.debug("HibernateDocumentRepository.getDocumentById("+id+")");
		Document document = (Document) getHibernateTemplate().get(Document.class, id);
		log.debug(" ==> Document : " + document.getName());
		return document;
	}

	@Override
	public void saveDocument(Document document) {
		getHibernateTemplate().saveOrUpdate(document);
	}

	@Override
	public List<Document> getDocuments() {
		return getHibernateTemplate().loadAll(Document.class);
	}

}
